{extend name="public/nav" /}
{block name="title"} 档案管理系统 {/block}

{block name="content"}
<style>
    html,body{
        height: 100%;
    }
    input{
        border: none;
    }
    .layui-input-block{
        margin-left: 0px;
    }
    .layui-form-select dl dd.layui-this {
        background-color: #1296db;
        color: #fff;
    }
    #img img{
        width: 120px;
        height: 120px;
        border-radius: 250px;
    }
    .layui-btn-color{
        background-color: transparent;
        color: #2D93CA;
        font-weight: bold;
        display: block;
        width: 100%;
        border: 1px solid #1296db;
    }
    .upload-img{
        width: 30.5%;
        padding: 1%;
        border: 1px solid #ccc;
        text-align: center;
        float: left;
    }
    .upload-img img{
        height: 60px;
        margin-bottom: 5px;
    }
</style>
<div class="site-content" style="background-color: #cccccc;">
    <div class="site-h1">
        <i class="layui-icon layui-icon-left" onclick="window.location.href='/'"></i>档案添加
    </div>
    <div class="layui-container">
        <div class="site-text" style="margin-top: 30px;">
            <form class="layui-form" method="post">
                <div class="layui-form-item">
                    <div>档案名称</div>
                    <div class="layui-input-block">
                        <input type="text" name="name" required lay-verify="required" placeholder="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>分公司</div>
                    <div class="layui-input-block">
                        <select name="enter_id">
                            {foreach $branch as $p}
                            <option value="{$p.id}">{$p.branch_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>管道段</div>
                    <div class="layui-input-block">
                        <select name="pipe_id">
                            {foreach $pipes as $p}
                            <option value="{$p.unit_id}">{$p.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>上传图片</div>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-color" id="pic_btn">
                            <i class="layui-icon">&#xe67c;</i>
                        </button>
                    </div>
                    <div id="pics" style="display: none;"></div>
                </div>
                <div class="layui-form-item">
                    <div>焊口编号</div>
                    <div class="layui-input-block">
                        <input type="text" name="order_id" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>桩号编号</div>
                    <div class="layui-input-block">
                        <input type="text" name="pile_number" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>施工日期</div>
                    <div class="layui-input-block">
                        <input type="text" name="const_time" id="const_time" required lay-verify="required"
                            placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>检测日期</div>
                    <div class="layui-input-block">
                        <input type="text" name="test_time" id="test_time" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>施工单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="const_unit" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>机组</div>
                    <div class="layui-input-block">
                        <input type="text" name="crew" required lay-verify="required" placeholder="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>焊材厂家</div>
                    <div class="layui-input-block">
                        <input type="text" name="manufactor" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>无损检测单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="ndt_unit" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>监理单位</div>
                    <div class="layui-input-block">
                        <input type="text" name="supervisor_unit" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>内检测里程</div>
                    <div class="layui-input-block">
                        <input type="text" name="mileage" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>内检测编号</div>
                    <div class="layui-input-block">
                        <input type="number" name="mileage_number" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div>排查结果</div>
                    <div class="layui-input-block">
                        <input type="text" name="Invest_res" required lay-verify="required" placeholder=""
                            autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-color" lay-submit lay-filter="add">保存</button>
                    </div>
                </div>
            </form>

            <script type="text/javascript">
                layui.use(['form', 'upload', 'jquery', 'laydate'], function () {
                    var form = layui.form,
                        upload = layui.upload,
                        layer = layui.layer,
                        $ = layui.jquery,
                        laydate = layui.laydate;
                    //上传
                    upload.render({
                        elem: '#pic_btn' //绑定元素
                        , url: '{:url("index/api/upload")}' //上传接口
                        , done: function (res) {
                            //上传完毕回调
                            if (res.code == 0) {
                                layer.msg('上传成功')
                                var imgHtml = '<div class="upload-img">' +
                                    '<input type="hidden" value="' + res.data.path + '" name="pic[]">' +
                                    '<img src="' + res.data.path + '" />' +
                                    '<button class="layui-btn layui-btn-xs del" data-url="' + res.data.path + '">删除</button>'
                                    + '</div>';
                                $('#pics').append(imgHtml).show();
                            } else {
                                layer.msg('上传失败')
                            }
                        }
                        , error: function () {
                            layer.msg('上传失败');
                        }
                    });
                    //日期初始化
                    laydate.render({
                        elem: '#const_time',
                    })

                    laydate.render({
                        elem: '#test_time',
                    })
                    //提交
                    form.on('submit(add)', function (data) {
                        $.post('{:url("index/archives/add")}', data.field, function (res) {
                            if (res.code == 0) {
                                layer.msg('保存成功', { icon: 6, time: 1000 }, function () {
                                    window.location.href = '{:url("index/archives/index")}';
                                })
                            } else {
                                layer.msg('保存失败');
                            }
                        }, 'json');
                        return false;
                    });
                })
            </script>
        </div>
    </div>
</div>
{/block}